package com.ruoyi.word.service.impl;

import com.ruoyi.common.domain.word.CommonWord;
import com.ruoyi.common.domain.word.CommonWordPhrase;
import com.ruoyi.word.dao.mapper.CommonWordPhraseMapper;
import com.ruoyi.word.service.ICommonWordPhraseService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommonWordPhraseServiceImpl implements ICommonWordPhraseService {

    @Autowired
    private CommonWordPhraseMapper dao;

    @Override
    public int saveByWord(CommonWord word, List<CommonWordPhrase> phraseList) {
        dao.deleteByWid(word.getId());
        if(CollectionUtils.isEmpty(phraseList)) {
            return 0;
        }
        phraseList.stream().forEach(phrase -> {
            dao.insertSelective(phrase);
        });
        return 1;
    }

    @Override
    public List<CommonWordPhrase> findByWid(Long wid) {
        return dao.findByWord(wid);
    }

    @Override
    public int deleteByWid(Long wid) {
        return dao.deleteByWid(wid);
    }
}
